﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--自适应界面,如果出现,在某些设备出现界面偏小的话,检查一下有没有加入这句 -->
    <meta http-equiv="Content-type" name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">

    <link href="../../../js/jqmobile/jquery.mobile-1.4.5.min.css" rel="stylesheet" />
    <script src="../../../js/jquery.min2.1.4.js"></script>
    <script src="../../../js/jqmobile/jquery.mobile-1.4.5.min.js"></script>
    <script src="../../../js/cordova-1.5.0.js"></script>
    <script src="../../../js/jshelp.js"></script>

    <script>
        var clickCount = 1;
        //接受传参
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(decodeURI(r[2])); return null; //返回参数值
        }
        var customerCode = getUrlParam('customerCode');
        var mobile = getUrlParam('mobile');
        var djbhs = "";
        //根据登录手机号获取默认地址信息
        $(function () {
            $.get("ashx/list.ashx?type=get_address_bycode&customerCodes=" + customerCode + "&mobiles=" + mobile + "&a=" + Math.random(),
                { Action: "get" },
                function (data, textStatus) {
                    var dpcodename = data.item[0].loginid + "[" + data.item[0].username + "]";
                    $("#txt_storename").val(dpcodename);
                    $("#txt_shr").val(data.item[0].contacter);
                    $("#txt_phone").val(data.item[0].phone);
                    $("#txt_address").val(data.item[0].storeaddress);
                }
            )
        })
        //点击选择按钮
        $(document).delegate('#pageone', 'pageinit', function () {
            $(this).find('#select_dp').bind('click', function () {
                $.ajax({
                    type: "post",
                    async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                    url: "ashx/list.ashx?type=searchname",
                    data: { customerCodes: customerCode },
                    dataType: "json",        //返回数据形式为json
                    success: function (data) {
                        var str = "";
                        str += ' <legend>请选择店铺：</legend>';
                        for (var i = 0; i < data.item.length; i++) {
                            str += '<label for="' + data.item[i].code + '">' + data.item[i].name + '</label>';
                            str += '<input type="radio" name="gender" id="' + data.item[i].code + '" onchange="seldpname(\'' + data.item[i].code + '\',\'' + data.item[i].name + '\',\'' + data.item[i].address2 + '\',\'' + data.item[i].contacter + '\',\'' + data.item[i].phone + '\')"  value=' + data.item[i].code + '>';
                        }
                        $("#sel_dp").html(str);
                        $("#sel_dp").trigger('create');      //解决列表样式丢失！
                    }
                });
            });

            $(this).find('#select_dz').bind('click', function () {
                var loginLoadIndex = layer.load(2);
                $.ajax({
                    type: "get",
                    async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                    url: "ashx/list.ashx?type=get_request_list&customerCodes=" + customerCode + "&mobiles=" + mobile + "&a=" + Math.random(),
                    data: {},
                    dataType: "json",        //返回数据形式为json
                    success: function (data) {
                        var str = "";
                        if (data.item.length > 0) {
                            for (var i = 0; i < data.item.length; i++) {
                                str += '<li>';
                                str += '<div id="findstorename" class="ui-grid-a">';
                                str += '<div class="ui-block-a">';
                                str += '<h3> ' + data.item[i].username + '</h3>';
                                str += '</div>';
                                str += '<div class="ui-block-b">';
                                str += '<p>单号：' + data.item[i].docno + '</p>';
                                str += '</div>';
                                str += '</div>';
                                str += '<div class="ui-grid-a">';
                                str += '<p style="white-space:normal;">地址：' + data.item[i].takeaddress + '</p>';
                                str += '</div>';
                                str += '<div id="findlxr" class="ui-grid-a">';
                                str += '<div class="ui-block-a">';
                                str += '<p>联系人：' + data.item[i].takeman + '</p>';
                                str += '</div>';
                                str += '<div class="ui-block-b">';
                                str += '<p>联系方式：' + data.item[i].takephone + '</p>';
                                str += '</div>';
                                str += '</div>';
                                str += '<div id="findsl" class="ui-grid-a">';
                                str += '<div class="ui-block-a">';
                                str += '<p>发布数量：' + data.item[i].sl + '</p>';
                                str += '</div>';
                                str += '<div class="ui-block-b">';
                                str += '<p>抢单数量：' + data.item[i].qdsl + '</p>';
                                str += '</div>';
                                str += '<div class="ui-block-c">';
                                str += '<p>' + data.item[i].createtime + '</p>';
                                str += '</div>';
                                str += '</div>';
                                str += '<div data-role="navbar">';
                                str += '<ul>';
                                str += '<li><a href="#" data-transition="turn" onclick="speed(\'' + data.item[i].docno + '\')">处理进度</a></li>';
                                str += '<li><a href="#" data-transition="turn" onclick="productlist(\'' + data.item[i].docno + '\')">货品详情</a></li>';
                                if (data.item[i].zt == "草稿") {
                                    str += '<li><a href="" data-transition="turn" style="color:white;background-color:cadetblue;" onclick="fabu(' + data.item[i].id + ')">' + data.item[i].zt + '</a></li>';
                                }
                                else if (data.item[i].zt == "已发布") {
                                    str += '<li><a href="#" style="color:white;background-color:crimson;">' + data.item[i].zt + '</a></li>';
                                }
                                str += '</ul>';
                                str += '</div>';
                                str += '</li>';
                            }
                        }
                        else {
                            str += '<li>';
                            str += '<h3 style="text-align:center;color:red;" >无数据</h3>';
                            str += '</li>';
                        }
                        $("#thelist").html(str);
                        //解决列表样式丢失！
                        $("#thelist").trigger('create');
                        $("#thelist").listview("refresh");
                        layer.close(loginLoadIndex);
                    }
                });
            })
        });
        //$(document).delegate('#pagetwo', 'pageshow', function () {
        //    debugger
        //    $(this).find('#btn_back').bind('click', function () {
        //        debugger
        //    })

        //});
        //选择店铺
        function seldpname(dpcode, dpname, dpaddress, dpcontacter, dpphone) {
            customerCode = dpcode;
            $("#txt_storename").val(dpcode + "[" + dpname+"]");
            $("#txt_shr").val(dpcontacter);
            $("#txt_phone").val(dpphone);
            $("#txt_address").val(dpaddress);
            //history.back(-1); 
        }
        //验证条码
        var arrtm = [];
        var addclickCount = 0;
        function yztm() {
            var loginLoadIndex = layer.load(2);
            $.get("ashx/list.ashx?type=get_tm&tms=" + $("#txt_tm").val() + "&customerCodes=" + customerCode + "&r=" + Math.random(),
                { Action: "get" },
                function (data, textStatus) {
                    if (data.flag == true) {
                        layer.close(loginLoadIndex);
                        arrtm.push(data.tmid);
                        if (arrRepeat(arrtm)) {
                            layer.msg("此条码已经添加过，不能重复添加", function () {
                                time: 30000
                            });
                            arrtm.pop();
                        }
                        else {
                            var yz_zzs = /^[1-9]*[1-9][0-9]*$/;
                            layer.prompt({
                                formType: 0,//这里依然指定类型是多行文本框，但是在下面content中也可绑定多行文本框
                                btn: ['确定', '取消'],
                                title: '填写数量',
                                area: ['50px', '100px'],
                                btnAlign: 'c',
                                content: '<div><input name="txt_sl" id="sl" class="layui-input"></div>',
                                yes: function (index, layero) {
                                    var value1 = $('#sl').val();//获取数量
                                    if (!yz_zzs.test(parseInt(value1))) {
                                        arrtm.removeByValue(data.tmid);
                                        layer.msg('必须是大于0的正整数！', { icon: 5 });
                                        return false;
                                    }
                                    else {
                                        layer.close(index);
                                        $("#txt_tm").val("")
                                        addclickCount++;
                                        var str = '';
                                        str += '<tr id="tr' + addclickCount + '">';
                                        str += '<td style="width:0%;display:none;">' + data.tmid + '</td>';
                                        str += '<td>' + data.bjwm + '</td>';
                                        str += '<td>' + value1 + '</td>';
                                        str += '<td><a href = "#" onclick = "removekh(' + addclickCount + ')" data-role="button" data-icon="delete">删除</a></td >';
                                        str += '</tr>';
                                        $("#productlist").append(str).trigger("create");
                                    }
                                },
                                btn2: function () {
                                    arrtm.removeByValue(data.tmid);
                                }, cancel: function () {
                                    arrtm.removeByValue(data.tmid);
                                }, end: function () {

                                }
                            });
                        }
                    }
                    else {
                        layer.msg(data.msg, function () {
                            time: 30000
                        });
                        layer.close(loginLoadIndex);
                    }
                }
            )
        }
        //验证是否有重复条码
        function arrRepeat(arr) {
            var arrStr = JSON.stringify(arr), str;
            for (var i = 0; i < arr.length; i++) {
                if (arrStr.indexOf(arr[i]) != arrStr.lastIndexOf(arr[i])) {
                    return true;
                }
            };
            return false;
        }
        //删除指定行
        function removekh(delrow) {
            var trarr = $("#tr" + delrow + "").children();  //获取改行所有td
            var tdtm = trarr.eq(0).text()//获取改行的值
            arrtm.removeByValue(tdtm);
            $("#tr" + delrow + "").remove(); //根据行id移除该行
        }
        //删除数组指定元素
        Array.prototype.removeByValue = function (val) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == val) {
                    this.splice(i, 1);
                    break;
                }
            }
        }
        //正则表达式
        var reg = /^\d+(\.\d+)?$/; //只能为数字
        var msg = "只能填写数字!";
        function saveandtj(lx) {
            var txt_shr = $("#txt_shr").val();//收货人
            var txt_phone = $("#txt_phone").val();//收货人手机号
            var txt_address = $("#txt_address").val();//收货地址
            var txt_remark = $("#txt_remark").val();//备注
            if (txt_shr == "" || txt_shr == undefined || txt_shr == null) {
                layer.msg("请填写收货人姓名", { time: 2000 })
                return false;
            }
            if (txt_phone == "" || txt_phone == undefined || txt_phone == null) {
                layer.msg("请填写手机号", { time: 2000 });
                return false;
            }
            if (txt_address == "" || txt_address == undefined || txt_address == null) {
                layer.msg("请填写收货地址", { time: 2000 });
                return false;
            }
            var ArrayObj_mx = new Array();
            var obj = document.getElementById("myTable");
            var rows = obj.rows;
            if (rows.length < 2) {
                layer.msg("请填写要调拨的条码明细！", { time: 2000 });
                return false;
            }
            else {
                for (var i = 1; i < rows.length; i++) { //由于第一行一般为标题，所以从第二行开始获取值）
                    var tmid = rows[i].cells[0].innerHTML;
                    var sl = rows[i].cells[2].innerHTML;
                    var mx = {
                        "tmid": tmid,
                        "sl": sl
                    };
                    ArrayObj_mx.push(mx);
                }
                //添加基本信息1
                var ArrayObj_main = new Array();
                var main = {
                    "customerCode": customerCode,
                    "mobile": mobile,
                    "shr": txt_shr,
                    "phone": txt_phone,
                    "address": txt_address,
                    "remark": txt_remark
                };
                ArrayObj_main.push(main);
                if (ArrayObj_main.length > 0 && ArrayObj_mx.length > 0) {
                    //防止多次点击
                    if (clickCount >= 2) {
                        return false;
                    }
                    else {
                        var loginLoadIndex = layer.load(2);
                        $.ajax({
                            type: "post",
                            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                            url: "ashx/list.ashx?type=requestsaveandtj&lxs=" + lx + "&djbhs=" + djbhs,
                            data: JSON.stringify({ 'ArrayObj_main': ArrayObj_main, 'ArrayObj_mx': ArrayObj_mx }),
                            dataType: "json",        //返回数据形式为json
                            success: function (data) {
                                if (data.flag == "True") {
                                    layer.close(loginLoadIndex);
                                    clickCount++;
                                    djbhs = data.djbh;
                                    layer.msg(data.remsg, {
                                        time: 2000,
                                        end: function () {
                                            location.href = "sq_list.html?customerCode=" + customerCode + "&mobile=" + mobile;;
                                        }
                                    })
                                }
                                else {
                                    layer.close(loginLoadIndex);
                                    layer.msg(data.remsg, function () {
                                        time: 30000
                                    });
                                }
                            }
                        });
                    }
                }
                else {
                    layer.msg("失败，请联系系统管理员！", function () {
                        time: 30000
                    });
                }
            }
        }
        //自动转为大写
        function toUpperCase(obj) {
            obj.value = obj.value.toUpperCase()
        }
    </script>
    <style type="text/css">
        div#findBar.ui-grid-a .ui-block-a {
            width: 80%
        }

        div#findBar.ui-grid-a .ui-block-b {
            width: 20%
        }

        div#findIput.ui-grid-a .ui-block-a {
            width: 25%
        }

        div#findIput.ui-grid-a .ui-block-b {
            width: 75%
        }

        div#div_dpname.ui-grid-a .ui-block-a {
            width: 25%
        }

        div#div_dpname.ui-grid-a .ui-block-b {
            width: 55%
        }

        div#div_dpname.ui-grid-a .ui-block-c {
            width: 20%
        }

        body {
            margin: 0;
            padding: 0;
        }

        .table-responsive {
            max-width: 375px;
            overflow: auto;
            margin: 50px auto;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            border-spacing: 0;
            border: 0px solid #999;
            table-layout: fixed;
        }

        th, td {
            border: 0px solid #999;
        }

        td {
            padding: 0 4px;
            white-space: pre-line;
            word-break: break-all;
            word-wrap: break-word;
        }
        /*文本域填写三行*/
        textarea.ui-input-text {
            min-height: 80px;
        }
        /*隐藏table上方点击显示隐藏列功能按钮*/
        div#div_product1 a[href="#myTable-popup"] {
            display: none;
        }
    </style>
</head>
<body>
    <div data-role="page" id="pageone">
        <div data-role="header" data-position="fixed">
            <h1>新增</h1>
            <a href="#" class="ui-btn-left" data-rel="back">返回</a>
        </div>
        <div data-role="content" class="ui-content">
            <form method="post" action="">
                <div class="ui-field-contain" data-role="fieldcontain">
                    <div id="div_dpname" class="ui-grid-a">
                        <div class="ui-block-a">
                            <label for="lname">店铺名称</label>
                        </div>
                        <div class="ui-block-b">
                            <input type="text" name="lname" id="txt_storename" disabled="disabled" data-clear-btn="true">
                        </div>
                        <div class="ui-block-c">
                            <a href="#pagetwo" id="select_dp" class="ui-btn ui-btn-inline" data-mini="true">选择</a>
                        </div>
                    </div>
                    <div id="findIput" class="ui-grid-a">
                        <div class="ui-block-a">
                            <label for="lname">收货人</label>
                        </div>
                        <div class="ui-block-b">
                            <input type="text" name="lname" id="txt_shr" placeholder="填写收货人..." data-clear-btn="true">
                        </div>
                        <!--<div class="ui-block-c">
                            <a href="#page_address_manage" id="select_dz" class="ui-btn ui-btn-inline" data-mini="true">选择</a>
                        </div>-->
                    </div>
                    <div id="findIput" class="ui-grid-a">
                        <div class="ui-block-a">
                            <label for="lname">手机号码</label>
                        </div>
                        <div class="ui-block-b">
                            <input type="text" name="lname" id="txt_phone" placeholder="填写手机号码..." data-clear-btn="true">
                        </div>
                    </div>
                    <div id="findIput" class="ui-grid-a">
                        <div class="ui-block-a">
                            <label for="lname">收货地址</label>
                        </div>
                        <div class="ui-block-b">
                            <textarea name="txt_address" id="txt_address" placeholder="填写收货地址.." data-clear-btn="true"></textarea>
                        </div>
                    </div>
                    <div id="findIput" class="ui-grid-a">
                        <div class="ui-block-a">
                            <label for="lname">备注</label>
                        </div>
                        <div class="ui-block-b">
                            <textarea name="txt_remark" id="txt_remark" placeholder="填写备注.." data-clear-btn="true"></textarea>
                        </div>
                    </div>
                    <!--<label for="lname">拆分发货</label>
                    <input type="checkbox" data-role="flipswitch" name="switch" id="switch" checked>-->
                    <!--<label for="lname">快递类型</label>
                    <select name="kdlx" id="kdlx">
                        <option value="sfbj">顺丰标件</option>
                    </select>-->
                </div>

                <p style="color:red;">温馨提示：请把相同收货地址的货品集中在同一单下单，否则会产出额外的快递费用！！！</p>
                <div id="findBar" class="ui-grid-a">
                    <div class="ui-block-a">
                        <input type="text" onkeyup="toUpperCase(this)" data-inline="true" name="lname" id="txt_tm" placeholder="填写条形码..." data-clear-btn="true">
                    </div>
                    <div class="ui-block-b">
                        <a href="#" onclick="yztm()" class="ui-btn ui-btn-inline" data-mini="true">确定</a>
                    </div>
                </div>
                <div data-role="fieldcontain" class="data-table" id="div_product1">
                    <table data-role="table" data-mode="columntoggle" class="ui-responsive" data-column-btn-text="点我显示或隐藏列!" id="myTable">
                        <thead>
                            <tr>
                                <th style="display:none;">条码id</th>
                                <th style="width:65%">条码</th>
                                <th style="width:15%">数量</th>
                                <th style="width:20%">操作</th>
                            </tr>
                        </thead>
                        <tbody id="productlist"></tbody>
                    </table>
                </div>
            </form>
        </div>
        <div data-role="footer" style="text-align:center;" data-position="fixed">
            <a href="#" onclick="saveandtj('save')" class="ui-btn ui-corner-all ui-shadow ui-icon-plus ui-btn-icon-left">保存</a>
            <a href="#" onclick="saveandtj('tj')" class="ui-btn ui-corner-all ui-shadow ui-icon-plus ui-btn-icon-left">发布</a>

        </div>
    </div>
    <div data-role="page" data-dialog="true" id="pagetwo">
        <div data-role="header" data-theme="a">
            <h1>选择店铺</h1>
        </div>
        <div data-role="main" class="ui-content">
            <div data-role="fieldcontain">
                <fieldset data-role="controlgroup" id="sel_dp">
                    <!--<legend>请选择店铺：</legend>
                    <label for="1331">朝阳渠道_李秀梅</label><input type="radio" name="gender" id="1331" onchange="seldpname('1331')" value=朝阳渠道_李秀梅>
                    <label for="133101">丽都名品广场</label><input type="radio" name="gender" id="133101" onchange="seldpname('133101')" value=丽都名品广场>
                    <label for="133102">建平丽都</label><input type="radio" name="gender" id="133102" onchange="seldpname('133102')" value=建平丽都>-->
                </fieldset>
            </div>
            <a href="#pageone" class="ui-btn ui-btn-inline">确定</a>
        </div>

        <!--<div data-role="footer" data-theme="a">
            <h1>对话框底部文本</h1>
        </div>-->
    </div>
    <div data-role="page" id="page_address_manage">
        <div data-role="header">
            <h1>地址管理</h1>
        </div>

        <div data-role="main" class="ui-content">
            <p>这是第二个页面。点击以下链接跳转到第一个页面。</p>
            <a href="#pageone">跳转到第一个页面</a>
        </div>

        <div data-role="footer">
            <h1>底部文本</h1>
        </div>
    </div>
</body>
<script src="../../../js/jquery.min2.1.4.js"></script>
<script src="../../../js/layer/layer.js"></script>
</html>
